<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="120px">
      <el-form-item label="用户id" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入用户id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="提现到的账号" prop="account">

        <el-input
          v-model="queryParams.account"
          placeholder="请输入提现到的账号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="提现方式" prop="isFrom">
        <el-select v-model="queryParams.isFrom" placeholder="请选择" clearable size="small">
          <el-option
            v-for="item in optiontxfs"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>

      </el-form-item>
      <el-form-item label="提现金额" prop="money">
        <el-input
          v-model="queryParams.money"
          placeholder="请输入提现金额"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核状态" prop="isStatus">
        <el-select v-model="queryParams.isStatus" placeholder="请选择" clearable size="small">
          <el-option
            v-for="item in optionshzt"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>

      </el-form-item>

      <el-form-item label="提现订单号" prop="rejectCode">
        <el-input
          v-model="queryParams.rejectCode"
          placeholder="请输入提现订单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>



    <el-table   height="550" style="width: 100%" v-loading="loading" :data="logList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="用户提现审核表" align="center" prop="rejectId"   width="180" show-overflow-tooltip/>


      <el-table-column label="用户id" align="center" prop="userId" width="100" show-overflow-tooltip />
      <el-table-column label="提现到的账号" align="center" prop="account" width="180" show-overflow-tooltip/>
      <el-table-column label="提现方式" align="center" prop="isFrom" >
        <template slot-scope="scope">

          <span v-show="scope.row.isFrom==1">微信</span>
          <span v-show="scope.row.isFrom==2">支付宝</span>
        </template>
      </el-table-column>
      <el-table-column label="提现金额" align="center" prop="money" />
      <el-table-column label="审核状态" align="center" prop="isStatus" >
        <template slot-scope="scope">

          <span v-show="scope.row.isStatus==0">待审核</span>
          <span v-show="scope.row.isStatus==1">提现失败</span>
          <span v-show="scope.row.isStatus==2">驳回</span>
          <span v-show="scope.row.isStatus==3">通过</span>
        </template>
      </el-table-column>
      <el-table-column label="提现失败/驳回 原因" align="center" prop="rejectCause" width="180" show-overflow-tooltip />
      <el-table-column label="真实姓名" align="center" prop="realName" />
      <el-table-column label="提现订单号" align="center" prop="rejectCode" width="180" show-overflow-tooltip />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <!-- <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template> -->
      </el-table-column>
      <!-- <el-table-column label="更新时间" align="center" prop="updateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" width="180" show-overflow-tooltip /> -->
      <el-table-column fixed="right" width="150"  label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            v-show="scope.row.isStatus==0 || scope.row.isStatus==1"
            icon="el-icon-coordinate"
            @click="handleUpdate(scope.row,1)"
          >审批</el-button>
          <el-button
            size="mini"
            type="text"
            v-show="scope.row.isStatus==0 || scope.row.isStatus==1"
            icon="el-icon-coordinate"
            @click="handleUpdate(scope.row,2)"
          >驳回</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改用户提现审核对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="提现到的账号" >
          <el-input
            v-model="form.account"
            placeholder="请输入提现到的账号"
            disabled
            size="small"
          />
        </el-form-item>
        <el-form-item label="提现方式" >
          <el-select style="width: 100%;" disabled v-model="form.isFrom" placeholder="" clearable size="small">
            <el-option
              v-for="item in optiontxfs"
              :key="item.value"

              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="提现金额" >
          <el-input
            v-model="form.money"
            placeholder=""
            disabled
            size="small"
          />
        </el-form-item>
        <el-form-item label="真是姓名" >
          <el-input
            v-model="form.realName"
            placeholder=""
            disabled
            size="small"
          />
        </el-form-item>
        <el-form-item label="驳回原因" v-show="title=='驳回'" >
          <el-input
            v-model="form.rejectCause"
            placeholder=""
            size="small"
          />
        </el-form-item>


      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listLog, getLog, delLog, addLog, updateLog, exportLog } from "@/api/lanbangkeji/user/tixianguanli";

export default {
  name: "Log",
  components: {
  },
  data() {
    return {
      shenehobj:{},
      //审核状态 0待审核 1提现失败 2驳回 3通过
      optionshzt:[
        {value:0,label:'待审核'},
        {value:1,label:'提现失败'},
        {value:2,label:'驳回'},
        {value:3,label:'通过'},
      ],
      //提现方式 1微信 2支付宝
      optiontxfs:[
        {value:1,label:'微信'},
        {value:2,label:'支付宝'},
      ],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户提现审核表格数据
      logList: [],
      // 弹出层标题
      title: "审核",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        account: null,
        isFrom: null,
        money: null,
        isStatus: null,
        rejectCause: null,
        rejectCode: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询用户提现审核列表 */
    getList() {
      this.loading = true;
      listLog(this.queryParams).then(response => {
        this.logList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        rejectId: null,
        remark: null,
        createTime: null,
        updateTime: null,
        userId: null,
        account: null,
        isFrom: null,
        money: null,
        isStatus: "0",
        rejectCause: null,
        realName: null,
        rejectCode: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.rejectId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加用户提现审核";
    },

    /** 修改按钮操作 */
    handleUpdate(row,item) {
      this.shenehobj = row
      this.reset();
      const rejectId = row.rejectId
      getLog(rejectId).then(response => {
        this.form = response.data;
        this.open = true;
        if(item==1){
          this.title = "审核";
        }else {
          this.title = "驳回";
        }

      });
    },
    /** 提交按钮 */
    submitForm() {
      debugger
      if(this.title=='驳回'){
        if(!this.form.rejectCause){
          this.$message({
            message: '请填写驳回原因',
            type: 'warning'
          });
          return
        }
        this.shenehobj.isStatus = 2
        this.shenehobj.rejectCause = this.form.rejectCause
        updateLog(this.shenehobj).then(response => {
          this.msgSuccess("驳回成功");
          this.open = false;
          this.getList();
        });
      }else {
        this.shenehobj.isStatus = 3
        updateLog(this.shenehobj).then(response => {
          this.msgSuccess("审评成功");
          this.open = false;
          this.getList();
        });
      }


    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const rejectIds = row.rejectId || this.ids;
      this.$confirm('是否确认驳回用户提现审核编号为"' + rejectIds + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return delLog(rejectIds);
      }).then(() => {
        this.getList();
        this.msgSuccess("驳回成功");
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有用户提现审核数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return exportLog(queryParams);
      }).then(response => {
        this.download(response.msg);
      })
    }
  }
};
</script>
